A Tour of C++ by Bjarne Stroustrup

A Tour of C++ by Bjarne Stroustrup

Author:Bjarne Stroustrup
Language: eng
Format: epub, pdf
Publisher: Pearson Education
Published: 2018-03-13T16:00:00+00:00


9.5 Advice

[1] Use std::string to own character sequences; §9.2; [CG: SL.str.1].

[2] Prefer string operations to C-style string functions; §9.1.

[3] Use string to declare variables and members rather than as a base class; §9.2.

[4] Return strings by value (rely on move semantics); §9.2, §9.2.1.

[5] Directly or indirectly, use substr() to read substrings and replace() to write substrings; §9.2.

[6] A string can grow and shrink, as needed; §9.2.

[7] Use at() rather than iterators or [ ] when you want range checking; §9.2.

[8] Use iterators and [ ] rather than at() when you want to optimize speed; §9.2.

[9] string input doesn’t overflow; §9.2, §10.3.

[10] Use c_str() to produce a C-style string representation of a string (only) when you have to; §9.2.

[11] Use a stringstream or a generic value extraction function (such as to<X>) for numeric conversion of strings; §10.8.

[12] A basic_string can be used to make strings of characters on any type; §9.2.1.

[13] Use the s suffix for string literals meant to be standard-library strings; §9.3 [CG: SL.str.12].

[14] Use string_view as an argument of functions that needs to read character sequences stored in various ways; §9.3 [CG: SL.str.2].

[15] Use gsl::string_span as an argument of functions that needs to write character sequences stored in various ways; §9.3. [CG: SL.str.2] [CG: SL.str.11].

[16] Think of a string_view as a kind of pointer with a size attached; it does not own its characters; §9.3.

[17] Use the sv suffix for string literals meant to be standard-library string_views; §9.3.

[18] Use regex for most conventional uses of regular expressions; §9.4.

[19] Prefer raw string literals for expressing all but the simplest patterns; §9.4.

[20] Use regex_match() to match a complete input; §9.4, §9.4.2.

[21] Use regex_search() to search for a pattern in an input stream; §9.4.1.

[22] The regular expression notation can be adjusted to match various standards; §9.4.2.

[23] The default regular expression notation is that of ECMAScript; §9.4.2.

[24] Be restrained; regular expressions can easily become a write-only language; §9.4.2.

[25] Note that \i allows you to express a subpattern in terms of a previous subpattern; §9.4.2.

[26] Use ? to make patterns “lazy”; §9.4.2.

[27] Use regex_iterators for iterating over a stream looking for a pattern; §9.4.3.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.